<template>
    <div>
        <el-collapse class="collapseList" v-model="activeNames" accordion v-if="readyShow">
            <el-collapse-item title="申报信息" name="1">
                <basics :form="basics" :showAmend="showAmend" :showTemporary="showTemporary"></basics>
            </el-collapse-item>
            <el-collapse-item :title="'审核结果 ( '+trial.checkedOp+' )'" name="2" v-if="showTrail">
                <trial :showTwoButton="showTwoButton" :showReplenishButton="showReplenishButton"
                       :showDissent="showDissent" :form="trial"></trial>
            </el-collapse-item>
            <el-collapse-item title="我的异议" name="3" v-if="showDissent">
                <dissent :showDissent="showDissent" :showDissentButton="showDissentButton"
                         :form="dissent"></dissent>
            </el-collapse-item>
            <el-collapse-item :title="'异议审核结果 ( '+recheck.checkedOp+ ' )'" name="4" v-if="showRecheck">
                <recheck :showRecheckButton="showRecheckButton"
                         :form="recheck"></recheck>
            </el-collapse-item>
            <el-collapse-item title="法院审核结果" name="5" v-if="showAdjudication">
                <adjudication :form="adjudication"></adjudication>
            </el-collapse-item>
        </el-collapse>
    </div>
</template>

<script>
    import Basics from 'components/credit/basic/basics'
    import Trial from 'components/credit/trail/trial'
    import Dissent from 'components/credit/dissent/dissent.vue'
    import Recheck from 'components/credit/recheck/recheck'
    import Adjudication from 'components/credit/adjudication/adjudication'
    import util from 'assets/js/util.js'

    export default {
        data() {
            return {
                activeNames: '1',
                readyShow: false,
                showTwoButton: false,
                showReplenishButton: false,
                showAmend: false,
                showButton: false,
                showTemporary: false,
                showRecheckButton: false,

                showDissent: false,
                showTrail: false,
                showRecheck: false,
                showAdjudication: false,
                showDissentButton: false,
                basics: {
                    fileList: [],
                    temporaryTotal: '',
                    creditNature: '',
                    undecidedTotal: '',
                    basics_form: {
                        creditNature: '0',
                        mainObligor: '',
                        relatedObligor: '',
                        creditType: '0',
                        giveFirst: '0',
                        guaranteeCond: '',
                        guaranteeForm: '0'
                    },
                    basics_item: {
                        declarePrincipal: 0,
                        declareInterest: 0,
                        declareOther: 0,
                        declareTotal: 0,
                        declareNote: '',
                        declareProcess: '',
                    },
                },
                trial: {
                    trialList: [],
                    checkedNote: '',
                    specialNote:'',
                },
                dissent: {
                    fileList: [],
                    declareNote: '',
                },
                recheck: {
                    fileList: [],
                    declareNote: '',
                    recheckList: [],
                    checkedNote: '',
                    //secondReceiverName: '',
                    specialNote: '',
                },
                adjudication: {
                    adjudicationList: [],
                    fileList: [],
                    checkedNote: '',
                    specialNote:'',
                    //thirdReceiverName: '',
                },
                caseId: 0,
                creditorId: 0
            }
        },
        mounted() {
           // this.caseId = util.getUrlParam(document.location.href, 'caseId');
           // this.creditorId = util.getUrlParam(document.location.href, 'creditorId');
            this.id = util.getUrlParam(document.location.href, 'id');

            const _self = this;
            util.ajax({
                url: `/credit/info`,
                params: {id: util.getUrlParam(document.location.href, 'id')},
                success: function (data) {
                    //基础信息：creditDeclareFirstVO  一审：creditCheckFirstVO  二审：creditCheckSecondVO  三审：creditCheckThirdVO
                    //异议：creditCheckThirdVO

                    //基础信息：creditDeclareFirstVO

                    _self.basics.basics_form.creditNature = _self.matchTypeText(data.data.creditDeclareFirstVO.creditNature);
                    _self.basics.basics_form.creditType = _self.matchNatureText(data.data.creditDeclareFirstVO.creditType) || '';
                    _self.basics.basics_form.mainObligor = data.data.creditDeclareFirstVO.mainObligor;
                    _self.basics.basics_form.relatedObligor = data.data.creditDeclareFirstVO.relatedObligor || '';
                    _self.basics.basics_form.giveFirst = data.data.creditDeclareFirstVO.giveFirst === 0 ? '放弃' : '不放弃';
                    _self.basics.basics_form.guaranteeCond = data.data.creditDeclareFirstVO.guaranteeCond || '';
                    _self.basics.basics_form.guaranteeForm = _self.matchGuaranteeText(data.data.creditDeclareFirstVO.guaranteeForm) || '';

                    _self.basics.basics_item.declarePrincipal = data.data.creditDeclareFirstVO.declarePrincipal || 0;
                    _self.basics.basics_item.declareInterest = data.data.creditDeclareFirstVO.declareInterest || 0;
                    _self.basics.basics_item.declareOther = data.data.creditDeclareFirstVO.declareOther || 0;
                    _self.basics.basics_item.declareTotal = data.data.creditDeclareFirstVO.declareTotal || 0;
                    _self.basics.basics_item.declareNote = data.data.creditDeclareFirstVO.declareNote || '';
                    _self.basics.declareFileids = data.data.creditDeclareFirstVO.declareFileids;


                    if (data.data.creditDeclareFirstVO !== '') {
                        _self.readyShow = true;
                        _self.showTemporary = false;
                        if (data.data.creditDeclareFirstVO.creditorOp === 1) {
                            _self.showTemporary = true;
                            _self.showAmend = true;
                        }
                        _self.readyShow = true;
                    }

                    // 一审：creditCheckFirstVO,2

                    if (data.data.creditCheckFirstVO === '') {
                        _self.showTrail = false;
                        _self.readyShow = true;
                    } else {
                        if (data.data.creditCheckFirstVO.ccdList !== '') {
                            data.data.creditCheckFirstVO.ccdList.forEach(_credit => _self.trial.trialList.push({
                                checkedPrincipal: _credit.checkedPrincipal,
                                checkedInterest: _credit.checkedInterest,
                                checkedOther: _credit.checkedOther,
                                checkedTotal: _credit.checkedTotal,
                                creditNature: _self.matchTypeText(_credit.creditNature),
                            }));
                        }
                        _self.trial.checkedNote = data.data.creditCheckFirstVO.checkedNote || '';
                        _self.trial.specialNote = data.data.creditCheckFirstVO.specialNote || '';
                        _self.trial.checkedOp = _self.matchCheckedOp(data.data.creditCheckFirstVO.checkedOp);
                        _self.trial.creditorOp = data.data.creditCheckFirstVO.creditorOp;

                        if (data.data.creditCheckFirstVO.creditorOp === 1) {
                            _self.showTwoButton = true;
                        }
                        if (data.data.creditCheckFirstVO.creditorOp === 2) {
                            _self.showReplenishButton = true;
                            _self.readyShow = true;
                        }
                        _self.activeNames = '2';
                        _self.showTrail = true;
                        _self.readyShow = true;
                    }

                    //异议审核 :creditDeclareSecondVO
                    if (data.data.creditDeclareSecondVO === '') {
                        _self.showDissent = false;
                        _self.readyShow = true;
                    } else {
                        // _self.dissent.creditorOp = data.data.creditDeclareSecondVO.creditorOp;
                        _self.dissent.declareNote = data.data.creditDeclareSecondVO.declareNote || '';
                        _self.dissent.declareFileids = data.data.creditDeclareSecondVO.declareFileids;

                        if (data.data.creditDeclareSecondVO.creditorOp === 1) {
                            _self.showDissentButton = true;
                        }
                        _self.activeNames = '3';
                        _self.showDissent = true;
                        _self.readyShow = true;
                    }

                    //二审：creditCheckSecondVO，4

                    if (data.data.creditCheckSecondVO === '') {
                        _self.showRecheck = false;
                        _self.readyShow = true;
                    } else {
                        if (data.data.creditCheckSecondVO.ccdList !== '') {
                            data.data.creditCheckSecondVO.ccdList.forEach(_credit => _self.recheck.recheckList.push({
                                checkedPrincipal: _credit.checkedPrincipal,
                                checkedInterest: _credit.checkedInterest,
                                checkedOther: _credit.checkedOther,
                                checkedTotal: _credit.checkedTotal,
                                creditNature: _self.matchTypeText(_credit.creditNature),
                            }));
                        }
                        _self.recheck.declareNote = data.data.creditDeclareSecondVO.declareNote || '';
                        _self.recheck.declareFileids = data.data.creditDeclareSecondVO.declareFileids;
                        _self.recheck.checkedNote = data.data.creditCheckSecondVO.checkedNote || '';
                        _self.recheck.specialNote = data.data.creditCheckSecondVO.specialNote || '';
                        _self.recheck.creditorOp = data.data.creditCheckSecondVO.creditorOp;
                        _self.recheck.checkedOp = _self.matchCheckedOp(data.data.creditCheckSecondVO.checkedOp);

                        if (data.data.creditCheckSecondVO.creditorOp === 2) {
                            _self.showRecheckButton = true
                        }
                        _self.activeNames = '4';
                        _self.showRecheck = true;
                        _self.readyShow = true;
                    }

                    //法院：creditCheckThirdVO,5

                    if (data.data.creditCheckThirdVO === '') {
                        _self.showAdjudication = false;
                        _self.readyShow = true;
                    } else {
                        if (data.data.creditCheckThirdVO.ccdList !== '') {
                            data.data.creditCheckThirdVO.ccdList.forEach(_credit => _self.adjudication.adjudicationList.push({
                                checkedPrincipal: _credit.checkedPrincipal,
                                checkedInterest: _credit.checkedInterest,
                                checkedOther: _credit.checkedOther,
                                checkedTotal: _credit.checkedTotal,
                                creditNature: _self.matchTypeText(_credit.creditNature),
                            }));

                            _self.adjudication.checkedFileids = data.data.creditCheckThirdVO.checkedFileids || '';
                            _self.adjudication.checkedNote = data.data.creditCheckThirdVO.checkedNote || '';
                            _self.adjudication.specialNote = data.data.creditCheckThirdVO.specialNote || '';
                            _self.adjudication.creditorOp = data.data.creditCheckThirdVO.creditorOp;
                            _self.adjudication.checkedOp = data.data.creditCheckThirdVO.checkedOp;


                            _self.activeNames = '5';
                            _self.showAdjudication = true;
                        }
                        _self.readyShow = true;

                        // 状态(0:管理人新增待提交  1：初审确认  2：复审确认 3：法院裁判确认11：待审核，12：初审锁定，13：待主管理人初审结果确认，14：待债权人初审确认
                        // 21：待管理人二审   22：二审锁定中   23：待主管理人二审确认   24:待债权人二审确认)
                    }
                }
            })
        },
        methods: {
            matchNatureText: function (type) {
                let typeText = '';
                switch (type) {
                    case 1:
                        typeText = '金融借贷';
                        break;
                    case 2:
                        typeText = '民间借贷';
                        break;
                    case 3:
                        typeText = '货款';
                        break;
                    case 4:
                        typeText = '其他';
                        break;
                    default:
                        break;
                }
                return typeText;
            },
            matchTypeText: function (type) {
                let typeText = '';
                switch (type) {
                    case 1:
                        typeText = '职工债权';
                        break;
                    case 2:
                        typeText = '普通债权';
                        break;
                    case 3:
                        typeText = '税收债权';
                        break;
                    case 4:
                        typeText = '优先债权';
                        break;
                    default:
                        break
                }
                return typeText
            },
            matchGuaranteeText: function (type) {
                let typeText = '';
                switch (type) {
                    case '1':
                        typeText = '其他';
                        break;
                    case '2':
                        typeText = '抵押';
                        break;
                    case '3':
                        typeText = '质押';
                        break;
                    default:
                        break
                }
                return typeText
            },
            matchCheckedOp: function (type) {
                let typeText = '';
                switch (type) {
                    case 1:
                        typeText = '债权予以确认';
                        break;
                    case 2:
                        typeText = '要求补正材料';
                        break;
                    case 3:
                        typeText = '债权不予确认';
                        break;
                    default:
                        break
                }
                return typeText
            },
            matchCreditorOp: function (type) {
                let typeText = '';
                switch (type) {
                    case '0':
                        typeText = '不可操作';
                        break;
                    case '1':
                        typeText = '可操作';
                        break;
                    case '2':
                        typeText = '补充材料';
                        break;
                    default:
                        break;
                }
                return typeText;
            },
        },
        components: {Basics, Trial, Recheck, Adjudication, Dissent},
    }
</script>
